//
//  MBPageControlView.m
//  Meboo
//
//  Created by kyo on 2023/10/8.
//

#import "MBPageControlView.h"

@interface MBPageControlView ()

@property (nonatomic, strong) NSMutableArray *viewArr;

@end

@implementation MBPageControlView

#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Public Metohd
- (void)setIndex:(NSInteger)index {
    _index = index;
    for (int i = 0; i < 6; i++) {
        UIView *view = self.viewArr[i];
        if (i == index) {
            view.backgroundColor = HEXS(@"000000");
        } else {
            view.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:0.6];
        }
    }
}

#pragma mark - UI
- (void)setupUI {
    for (int i = 0; i < 6; i++) {
        UIView *pageView = [UIView new];
        pageView.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:0.6];
        if (i == 0) {
            pageView.backgroundColor = HEXS(@"000000");
        }
        pageView.layer.cornerRadius = MBHeightScale(2);
        [self addSubview:pageView];
        [pageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(MBWidthScale(16));
            make.height.mas_equalTo(MBHeightScale(4));
            if (i > 2) {
                make.bottom.equalTo(self);
            } else {
                make.top.equalTo(self);
            }
            
            if (i == 0 || i == 3) {
                make.left.equalTo(self);
            } else if (i == 2 || i == 5) {
                make.right.equalTo(self);
            } else {
                make.centerX.equalTo(self);
            }
        }];
        [self.viewArr addObject:pageView];
    }
}

#pragma mark - Setter && Getter
- (NSMutableArray *)viewArr {
    if (!_viewArr) {
        _viewArr = [NSMutableArray array];
    }
    return _viewArr;
}

@end
